var map_height_y : int = 50; // y
var map_width_x : int = 50; // x
var map_depth_z : int = 50; // z
var number_of_rooms : int = 100;
var template_generic : GameObject;

function Start (){
    // loads a map

    print("Starting map generator");
    // create array
    var map3d = new Array();
    
    // make it a 50x50x50 array
    for (x = 0; x < map_width_x + 1; x++){ // loop through 0 - 50
        
        var inner_map2d = new Array(); // add new row
        map3d.push(inner_map2d); // add a new column
        for (y = 0; y < map_height_y + 1; y++){
            inner_map2d.push(new Array());
            for (z = 0; z < map_depth_z + 1; z++){ 
                map3d[x][y][z] = 0; // set all points to 0
            }
        }
    }
    
    
    // loop through every room we need to make
    // set position, example: [20,20,20]
    var current_position = new Array();
    current_position[0] = map_width_x / 2;
    current_position[1] = map_height_y / 2;
    current_position[2] = map_depth_z / 2;
    
    map3d[current_position[0]][current_position[1]][current_position[2]] = 1; // set starting point to 1
    for (i = 0; i < number_of_rooms; i++){ // edit rooms up until the room limit
        random_value = Random.value;
        // get a random number between 0 and 5
        random_value_in_range = random_value * 6;
        // 0 = left, 1 = right, 2 = up, 3 = down, 4 = forwards, 5 = backwards
        integer_direction = Mathf.Floor(random_value_in_range);
        if (integer_direction == 0){
            // we move left
            if (current_position[0] > 0){
                current_position[0] -= 1;
            }
			else{
				number_of_rooms++;
			}
        }
        if (integer_direction == 1){
            // we move right
            if (current_position[0] < map_width_x){
                current_position[0] += 1;
            }
			else{
				number_of_rooms++;
			}
        }
        if (integer_direction == 2){
        
            // we move up
            if (current_position[1] > 0){
                current_position[1] -= 1;
            }
			else{
				number_of_rooms++;
			}
        }
        if (integer_direction == 3){
            // we move down
            if (current_position[1] < map_height_y){
                current_position[1] += 1;
            }
			else{
				number_of_rooms++;
			}
        }
        if (integer_direction == 4){
            // we move forwards
            if (current_position[2] < map_depth_z){
                current_position[2] += 1;
            }
			else{
				number_of_rooms++;
			}
        }
        if (integer_direction == 5){
            // we move backwards
            if (current_position[2] > 0){
                current_position[2] -= 1;
            }
			else{
				number_of_rooms++;
			}
        }

        
        // set the current poision to true on the map
         //if (map2d[current_position[0]][current_position[1]] == 0){
            //map2d[current_position[0]][current_position[1]] = 1;
         //}
         //if (map2d[current_position[0]][current_position[1]] == 1){
            //map2d[current_position[0]][current_position[1]] = 0;
         //}

		if (map3d[current_position[0]][current_position[1]][current_position[2]]  == 0){
			number_of_rooms++;
			}
		map3d[current_position[0]][current_position[1]][current_position[2]] = 1;
    }
    //print('ending positions');
    //print(current_position[0]);
    //print(current_position[1]);

    // output the map
    //for (i = 0; i < map_width2d; i += 1){
    //    print(map2d[i]);
    //}
    // output the map
    //print(map2d);
    
    // output the map
    for (x = 0; x < map_width_x - 1; x++){
        for (y = 0; y < map_height_y - 1; y++){
            for (z = 0; z < map_depth_z - 1; z++){
                if (map3d[x][y][z] == 1){
					   var block = Instantiate (template_generic, Vector3(x - map_width_x / 2, y - map_height_y / 2, z - map_depth_z / 2), Quaternion.identity);
                }
            }
        }        
    }
    
}